package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone    string `gorm:"type:char(11);not null;comment:'手机号'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
	Status   int    `gorm:"type:int;not null;comment:状态:1-正常,2-冻结"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}
func (u *User) GetUser(status, page, pageSize int) (userList []User, err2 error) {
	if status == 0 {
		DB.Offset((page - 1) * pageSize).Limit(pageSize).Find(&userList)
	} else {
		err = DB.Where("status = ?", status).Offset((page - 1) * pageSize).Limit(pageSize).Find(&userList).Error
	}
	return
}

func (u *User) UpdateStatus(status, id int) error {
	return DB.Model(&u).Where("id = ?", id).Update("status", status).Error
}
